package com.jake.hunter.pattern.observer;

import java.util.ArrayList;
import java.util.List;

public class NumericSubject {

    private List<BaseNumericObserver> observers = new ArrayList<>();

    private int state;

    public List<BaseNumericObserver> getObservers() {
        return observers;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        notifyAllObservers();
    }

    public void attach(BaseNumericObserver observer) {
        observers.add(observer);
    }

    public void notifyAllObservers() {
        for (BaseNumericObserver observer : observers) {
            observer.update();
        }
    }

}
